<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var convert = function (s, numRows) {
            if (numRows == 1) return s
            let arr = []
            let j = 0, flag = 'first'
            for (let i = 0; i < numRows; i++) {
                arr[i] = ''
            }
            for (let i = 0; i < s.length; i++) {
                if (flag == 'first') {
                    arr[j] += s[i]
                    flag = true
                    continue
                }
                if (j >= numRows - 1) { flag = false }
                if (j < 1) { flag = true }
                if (flag) { j++ } else j--
                arr[j] += s[i]
            }
            return arr.join('')
        };
    </script>
</body>

</html>